import { RigidBody } from "../behaviours/RigidBody";
import { getBehaviourClassByName } from "../engine";
import { AnimationRenderer } from "../engine/AnimationRenderer";
import { TextRenderer } from "../engine/TextRenderer";
import { boolean } from "../engine/validators/boolean";
import { number } from "../engine/validators/number";
import { string } from "../engine/validators/string";
import { binding, Binding, makeBinding } from "./Binding";
import { Life } from "./Life";
import { Sound } from "./sound";



export class AnimationBehaviour extends Binding {

    @number()
    @binding((prefabRoot, value) => {
        prefabRoot.children[0].getBehaviour(Life).LifePoint = value;
    })
    LifePoint: number;


    @string()
    @binding((prefabRoot, value) => {
        prefabRoot.children[0].getBehaviour(AnimationRenderer).source = value;
    })
    imageSource: string

    @string()
    @binding((prefabRoot, value) => {
        prefabRoot.children[0].getBehaviour(AnimationRenderer).source = value;
    })
    config: string

    @string()
    @binding((prefabRoot, value) => {
        prefabRoot.children[0].getBehaviour(AnimationRenderer).action = value;
        const sound=getBehaviourClassByName('Sound')
        if(sound.isOpen===true || sound.isOpen===undefined)
        if(value==="rightjump" && sound.isOpen === true || value === 'rightjump' && sound.isOpen === undefined){
            prefabRoot.children[0].getBehaviour(Sound).play();
        }
    })
    action: string;

    @number()
    @binding((prefabRoot, value) => {
        prefabRoot.getBehaviour(RigidBody).x = value;
    })
    x: number;

    @number()
    @binding((prefabRoot, value) => {
        prefabRoot.getBehaviour(RigidBody).y = value;
    })
    y: number;


    constructor() {
        super();
        makeBinding(this)
    }
}